package inet;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

/**
 * create by yongli on 2020-07-31 21:26
 * 定时向服务端发送信息
 */

public class ClientSocketTest {
    public static void main(String[] args) throws IOException, InterruptedException {
        // 没有connect过程吗？
        Socket socket = new Socket(InetAddress.getLocalHost(), 6780);
        OutputStream os = socket.getOutputStream();
        // socket可以说是全双工的，可以一边读，一边写，并且读和写都是阻塞的。
        while (true) {

            os.write("I can't leave\n".getBytes());
            // os.write("I can't leave".getBytes());
            os.flush();
            System.out.println("write to server");
            Thread.sleep(100);
        }

    }
}
